<%-- 
    Document   : index
    Created on : 03.Nis.2010, 13:36:55
    Author     : mkafkas
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <script src="http://static.ak.connect.facebook.com/connect.php/en_US" type="text/javascript"></script>
        <script src="js/jquery.js" type="text/javascript"></script>
        <title>Login Page</title>
        <script type="text/javascript">
            FB.init("696f62581a6a09ac5b17357f326fd399", "/YapmadanOlme/xd_receiver.htm");
                // {"ifUserConnected" : facebook_onlogin}

          function facebook_onlogin() {
                var user_box = document.getElementById("userBox");
                var userIDBox = document.getElementById("userID");
              // add in some XFBML. note that we set useyou=false so it doesn't display "you"
              user_box.innerHTML =
                  "<span>"
                + "<fb:profile-pic uid='loggedinuser' facebook-logo='false'></fb:profile-pic>"
                + "Welcome, <fb:name uid='loggedinuser' useyou='false'></fb:name>. You are signed in with your Facebook account."
                + "</span>";

              // because this is XFBML, we need to tell Facebook to re-process the document
              FB.XFBML.Host.parseDomTree();
             // userIDBox.innerHTML= FB.Connect.get_loggedInUser();
              var api=FB.Facebook.apiClient;
              var userID=FB.Connect.get_loggedInUser();
              api.fql_query("SELECT name,pic,pic_square FROM user WHERE uid="+userID,
                                function(rows){
                                   userIDBox.innerHTML = rows[0].name + " " + rows[0].pic+" "+rows[0].pic_square;
                                    sendToDatabase(rows[0].name,userID);
                            });

                  
                }
            function sendToDatabase(username,userID)
            {
                $.post("users", {name:username,id:userID,type:"1"}, function(xml) {
                             window.alert(xml);
                             window.location="home.jsp";
                    });
            }
        </script>
    </head>
    <body>
       
        <p id="userID"></p>
        <h1>Hello World!</h1>
    <div id="userBox"> </div>
            <br>
        <fb:login-button v="2" size="medium" onlogin="facebook_onlogin();">Connect with Facebook</fb:login-button>
    </body>
</html>
